<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--conf
<sample in_favorites="true">
	<product version="1.0" edition="std"/>
	<modifications>
		<modified date="080205"/>
	</modifications>
<sampledescription><![CDATA[ ]]></sampledescription></sample>
 --> 

<html>
<head>
	<title>Drag-and-drop between DataView and Grid</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	
<body>
	<h1>Drag-and-drop between DataView and Grid</h1>
	<table border="0" cellspacing="5" cellpadding="5">
		<tr><td>
			<div id="data_container1" style="border:1px solid #A4BED4; background-color:white;width:240px;height:396px;"></div>				
		</td><td>
			
		</td><td>
			<div id="data_container2" style="width:400px;height:396px;"></div>				
		</td></tr>				
	</table>

	<script>
		dhtmlx.compat("dnd");
		
		data = new dhtmlXDataView({
			container:"data_container1",
			type:{
				template:"#Package# : #Version#<br/>#Maintainer#",
				padding:5,
				height:40
			},
			drag:true,
			select:true
		});
		data.load("../common/data.xml");
		
		mygrid = new dhtmlXGridObject('data_container2');
		mygrid.setImagePath("../../../codebase/imgs/");
		mygrid.enableDragAndDrop(true);
		mygrid.setSkin("dhx_skyblue");

		mygrid.loadXML("../../dhtmlxGrid/common/gridH.xml");
		
		
		
		
		//drag from grid into the dataview
		data.attachEvent("onBeforeDrop",function(context){
			if (context.from == mygrid){
				this.add({
					Package:context.from.cells(context.source, 1).getValue(),
					Version:context.from.cells(context.source, 2).getValue(),
					Maintainer:"not defined"
				}, this.indexById(context.target||this.first()));
				context.from.deleteRow(context.source);
				return false;
			}
			return true;
		})
		
		//drag from dataview into the grid
		mygrid.attachEvent("onDrag",function(sid,tid,sobj,tobj){
			if (sobj.object && sobj.object == data){
				var d = data.get(sid);
				var index = mygrid.getRowIndex(tid);
				
				mygrid.addRow(mygrid.uid(), [sid, d.Package, d.Version], index);
				data.remove(sid);
				return false;
			}
			return true;
		})
		
	</script>
</body>
</html>

